package com.vx.vxbug.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.vx.vxbug.RoleConstants;
import com.vx.vxbug.entities.User;
import com.vx.vxbug.services.UserService;

@Controller
public class UserManagerController {

	@Autowired
	private UserService uS;

	@RequestMapping(value = { "/userManager" }, method = RequestMethod.GET)
	public String index(Model model) {
		model.addAttribute("users", uS.getAllUsers());
		return "userManager";
	}

	@RequestMapping(value = { "/addAdmin" }, method = RequestMethod.GET)
	public String addAdmin(Model model) {
		User b = new User("admin", "admin", "Igor Ivanovich", RoleConstants.ROLE_ADMIN,"ven1x17@gmail.com");
		uS.registerUser(b);
		model.addAttribute("users", uS.getAllUsers());
		return "redirect:userManager";
	}

	@RequestMapping(value = { "/addUser" }, method = RequestMethod.GET)
	public String add(Model model) {
		model.addAttribute("users", uS.getAllUsers());
		return "redirect:userManager";
	}

	@RequestMapping(value = { "/deleteUser" }, method = RequestMethod.GET)
	public String delete(Model model) {
		model.addAttribute("users", uS.getAllUsers());
		return "redirect:userManager";
	}
}
